package com.example.emos.wx.utils.shiro;

import com.sun.xml.internal.bind.v2.TODO;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

public class OAuth2Realm extends AuthorizingRealm {

    @Autowired
    private JwtUtil jwtUtil;

    /**
     * 判断token是不是封装的Oauth2Token对象
     * @param token
     * @return
     */
    @Override
    public boolean supports(AuthenticationToken token) {
        return token instanceof OAuth2Token;
    }

    /**
     * 授权方法
     * @param principalCollection
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {

        /**
         * 需要把判断用户授权的方法写在这里面
         */
        //TODO 查询用户的权限列表
        //TODO 把权限列表添加到info对象中
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();


        return simpleAuthorizationInfo;
    }

    /**
     * 认证方法
     * @param authenticationToken
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        /**
         * 需要把登陆认证的方法写在这里面
         */
        //TODO 从令牌中获取userId，然后检测该账户是否被冻结。
        //TODO 往info对象中添加用户信息、Token字符串
        SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();


        return simpleAuthenticationInfo;
    }
}
